var Mongolian = require("mongolian")

var server = new Mongolian(
	"mongo://10.0.31.20:27017",
	"mongo://10.0.31.21:27017"
);

var db = server.db("g8up-mongo-arxJSYP2")
db.auth( '7Xpzja8o', 'OmIpyy643O0e');

var posts = db.collection("log")

function insert(data) {
	posts.insert(data, function(err, content) {
		if (err) {
			console.log('Insert Error!');
			return;
		}
		console.log('insert', content);
	});
}

function show(count, callback) {
	posts.find(null, {
		_id: 0
	}).sort({
		_id: -1
	}).limit(count).toArray(function(err, post) {
		callback(post);
	});
}

exports.insert = insert;
exports.show = show;